package com.liy.supercloud.server.gateway.feign;

import com.liy.framework.common.extvo.ResultVO;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class SystemClientFallbackFactory implements FallbackFactory<SystemClient> {
    private static final Logger log = LoggerFactory.getLogger(SystemClientFallbackFactory.class);

    public SystemClientFallbackFactory() {
    }

    public SystemClient create(final Throwable e) {
        log.info("sys feign fallback; reason was: {}", e.getMessage());
        log.error(e.getMessage(), e);
        return new SystemClient() {
            public ResultVO queryRolePermission(String roleId) throws Exception {
                ResultVO resultVO = new ResultVO();
                resultVO.setMessage("系统服务异常：" + e.getMessage());
                resultVO.setStatus("500");
                resultVO.setSuccess(false);
                return resultVO;
            }
        };
    }
}
